﻿Public Class frmMpcEditor
    'Private m_frmNext As Form

    Private m_cIdou As New clsDbIdoHyo

    Private Sub frmMpcEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        frmInital.Enabled = False
        Me.Left = frmInital.Left - 15
        Me.Top = frmInital.Top + 10
        m_EquipInterface = GetIniFile("COMMUNICATION_MODE", "INTERFACE", "0", g_szInitFileName)
        m_EquipInstPattern = GetIniFile("COMMUNICATION_MODE", "INSTRUCTION_PATTERN", "00", g_szInitFileName)
        m_EquipInstMode = GetIniFile("COMMUNICATION_MODE", "INSTRUCTION_MODE", "0", g_szInitFileName)
        m_EquipProgTrans = GetIniFile("COMMUNICATION_MODE", "PROGRAM_TRANSFER", "0", g_szInitFileName)
        m_EquipCompProc = GetIniFile("COMMUNICATION_MODE", "COMPLETION_PROCESSING", "0", g_szInitFileName)
        m_EquipIPAddress = GetIniFile("COMMUNICATION_MODE", "IP_ADDRESS", "0.0.0.0", g_szInitFileName)
        m_EquipPort = GetIniFile("COMMUNICATION_MODE", "PORT_NO", "0000", g_szInitFileName)

        '設備インターフェース
        Select Case m_EquipInterface
            Case 0
                RadioButton1.Checked = True
            Case 1
                RadioButton2.Checked = True
                txtIPAddress.Text = m_EquipIPAddress
                txtPort.Text = m_EquipPort
            Case 2
                RadioButton3.Checked = True
                txtIPAddress.Text = m_EquipIPAddress
                txtPort.Text = m_EquipPort
        End Select

        '設備指示パターン
        ComboBox1.SelectedIndex = Mid(m_EquipInstPattern, 2, 1)

        '動作指示モード
        If m_EquipInstMode = 1 Then
            CheckBox1.Checked = True
        Else
            CheckBox1.Checked = False
        End If

        'テスタへのプログラム名転送
        Select Case m_EquipProgTrans
            Case 0
                RadioButton4.Checked = True
            Case 1
                RadioButton5.Checked = True
        End Select

        'ロット完成時処理
        ComboBox2.SelectedIndex = Mid(m_EquipCompProc, 1, 1)

    End Sub

    Private Sub frmMpcEditor_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frmInital.Enabled = True
    End Sub

    Private Sub btnRegist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegist.Click
        '設備インターフェース
        Select Case True
            Case RadioButton1.Checked
                m_EquipInterface = 0
            Case RadioButton2.Checked
                m_EquipInterface = 1
                m_EquipIPAddress = txtIPAddress.Text
                m_EquipPort = txtPort.Text
            Case RadioButton3.Checked
                m_EquipInterface = 2
                m_EquipIPAddress = txtIPAddress.Text
                m_EquipPort = txtPort.Text
        End Select

        '設備指示パターン
        m_EquipInstPattern = Mid(ComboBox1.SelectedItem, 1, 1)
        Select Case m_EquipInstPattern
            Case "0"
                m_EquipInstPattern = "00"
            Case "1"
                m_EquipInstPattern = "01"
            Case "2"
                m_EquipInstPattern = "02"
            Case "3"
                m_EquipInstPattern = "03"
            Case "4"
                m_EquipInstPattern = "04"
            Case "5"
                m_EquipInstPattern = "05"
            Case "6"
                m_EquipInstPattern = "06"
            Case "7" '2021/8/23 add miaojf
                m_EquipInstPattern = "07"'2021/8/23 add miaojf
            Case "98"
                m_EquipInstPattern = "98"
            Case "99"
                m_EquipInstPattern = "99"
        End Select

        '動作指示モード
        If CheckBox1.Checked = True Then
            m_EquipInstMode = 1
        Else
            m_EquipInstMode = 0
        End If

        'テスタへのプログラム名転送
        Select Case True
            Case RadioButton4.Checked
                m_EquipProgTrans = 0
            Case RadioButton5.Checked
                m_EquipProgTrans = 1
        End Select

        'ロット完成時処理
        m_EquipCompProc = Mid(ComboBox2.SelectedItem, 1, 1)

        If (m_EquipInstPattern = "" Or m_EquipCompProc = "") Then
            MsgBox("Error:No selected list1 or list2")
            Exit Sub
        End If


        If (m_EquipIPAddress = "" Or m_EquipPort = "") And RadioButton1.Checked = False Then
            MsgBox("Error:No input IPAddress or Port")
            Exit Sub
        End If
        PutIniFile("COMMUNICATION_MODE", "INTERFACE", m_EquipInterface, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "INSTRUCTION_PATTERN", m_EquipInstPattern, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "INSTRUCTION_MODE", m_EquipInstMode, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "PROGRAM_TRANSFER", m_EquipProgTrans, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "COMPLETION_PROCESSING", m_EquipCompProc, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "IP_ADDRESS", m_EquipIPAddress, g_szInitFileName)
        PutIniFile("COMMUNICATION_MODE", "PORT_NO", m_EquipPort, g_szInitFileName)
        frmInital.btnStartComplt.Enabled = True
        frmInital.btnSwap.Enabled = True
        Me.Close()
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked = False Then
            txtIPAddress.Enabled = True
            txtPort.Enabled = True
        ElseIf RadioButton1.Checked = True Then
            txtIPAddress.Enabled = False
            txtPort.Enabled = False
        End If
    End Sub

    Private Sub RadioButton2_3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
        If RadioButton2.Checked = False And RadioButton3.Checked = False Then
            txtIPAddress.Enabled = False
            txtPort.Enabled = False
        ElseIf RadioButton2.Checked = True Or RadioButton3.Checked = True Then
            txtIPAddress.Enabled = True
            txtPort.Enabled = True
        End If
    End Sub

End Class